#!/usr/bin/env node

//bmp  bit map 位图
const fs = require('fs');

// 从命令行参数获取图片文件名
const args = process.argv.slice(2);
if (args.length !== 1) {
  console.log('Usage: node 05-bmp-info.js <file_name>');
  process.exit(1);
}

const fileName = args[0];

// 检查文件是否存在
if (!fs.existsSync(fileName)) {
  console.error('Error: File does not exist.');
  process.exit(1);
}

fs.readFile('./nodejs-logo.bmp',function(err,buf){
    if(err) {
        console.log(err);
        process.exit(1);
    }
    if(buf.toString('ascii',0,2) === 'BM') {
        console.log('width:', buf.readInt32LE(0x12));
        console.log('height:', buf.readInt32LE(0x16));
        console.log('color depth:', buf.readInt16BE(0x1c));
    }
})

